using Rhino.Etl.Core;
using Rhino.Etl.Core.Operations;

namespace EtlDemo.Rhino.JobCounts.Aggregates
{
    public class JobCounter : AbstractAggregationOperation
    {
        protected override void Accumulate(Row row, Row aggregate)
        {
            aggregate["Affiliate"] = row["Affiliate"];

            // the first case
            if (aggregate["JobCount"] == null)
                aggregate["JobCount"] = 0;

            // accumulate the count
            aggregate["JobCount"] = ((int)aggregate["JobCount"]) + ((int)row["JobCount"]);
        }

        protected override string[] GetColumnsToGroupBy()
        {
            return new[] { "Affiliate" };
        }
    }
}